#!/usr/bin/python
# -*- coding: utf-8 -*-

from google.appengine.ext import db

class CUserBaseInfo:
    def __init__(self):
        self.UserKeyString = ''
        self.LoginName = ''
        self.LoginEmail = ''
        self.LoginID = ''
        self.NickName = ''
        self.OnlineState = 0             #0不在线 1在线 2隐身

class CUserTable(db.Model):
    ID = db.IntegerProperty()
    LoginID = db.StringProperty()
    LoginAccount = db.UserProperty()
    NickName = db.StringProperty(default='')        #该字段暂时不用，目前统一用 google 帐户的昵称
    Gender = db.IntegerProperty(default=0)          #0保密 1男 2女
    Photo = db.BlobProperty()
    HavePhoto = db.BooleanProperty(default=False)
    Country = db.StringProperty(default='')
    Address = db.StringProperty(default='')
    Latitude = db.FloatProperty()                   #纬度
    Longitude = db.FloatProperty()                  #经度
    GeoBoxes = db.StringListProperty()              #地图相关边界
    GroupNumber = db.IntegerProperty(default=0)     #参与的组的个数
    Power = db.StringListProperty(default = None)   #权限列表
    Language = db.StringProperty()                  #'zh-cn'中文 'en-us'英语; 一律小写
    Integral = db.IntegerProperty(default=0)        #积分
    Recommender = db.StringProperty()               #推荐人
    OnlineState = db.IntegerProperty()              #0不在线 1在线 2隐身
    AllowFriend = db.IntegerProperty(default=0)     #0允许别人添加 1需要自己同意 2不允许别人添加
    PublicType = db.IntegerProperty(default=0)      #0公开 1仅向朋友公开 2不公开
    RegistDate = db.DateTimeProperty(auto_now_add=True)

class CAdminConfig(db.Model):
    IntegralPreBlog = db.IntegerProperty(default = 2)           #每发表一个Blog的积分
    IntegralPreCommentOn = db.IntegerProperty(default = 1)      #每发表一个评论的积分
    IntegralPreJoin = db.IntegerProperty(default = 10)          #每成功介绍一个新人加入的积分
    IntegralRegister = db.IntegerProperty(default = 10)         #完善个人信息的积分

    MicroblogNeedAuditing = db.IntegerProperty(default = 0)     #0不需要审核 1需要审核
    AnonymousCanCommentON = db.IntegerProperty(default = 0)     #0匿名用户可以评论 1匿名用户不可以评论

class CMicroblogTable(db.Model):
    ID = db.IntegerProperty()
    Title = db.StringProperty()
    Content = db.StringProperty(multiline=True)
    SourceUrl = db.LinkProperty()
    LoginName = db.StringProperty()
    CommentOnNumber = db.IntegerProperty(default = 0)
    PublicType = db.IntegerProperty(default = 0)        #0公开 1仅向朋友公开 (CGroupTalkTable中忽略该字段) 2不公开
    AdminPublicType = db.IntegerProperty(default = 0)   #0未审核 1全公开 2本人和朋友公开 3本人公开 4本人也不可见
    SetTop = db.IntegerProperty(default = 0)            #置顶等级：0不置顶 >0为置顶等级
    Date = db.DateTimeProperty(auto_now_add=True)
    LastCommentOnDate = db.DateTimeProperty()

class CMicroblogCommentOnTable(db.Model):
    MicroblogTableKey = db.ReferenceProperty(CMicroblogTable)
    Content = db.StringProperty(multiline=True)
    LoginName = db.StringProperty()
    AdminPublicType = db.IntegerProperty(default = 0)   #0未审核 1全公开 2本人和朋友公开 3本人公开 4本人也不可见
    Date = db.DateTimeProperty(auto_now_add=True)


#class CTagTable(db.Model):
#    ID = db.IntegerProperty()
#    TagName = db.StringProperty()
#    TagLanguage = db.StringProperty(default='zh_CN')
#    LoginID = db.StringProperty(default='')             #如果为''则为系统定义的

class CSearchKeyTable(db.Model):
    TagName = db.StringProperty()
    TagLanguage = db.StringProperty(default='zh_CN')
    SearchNumber = db.IntegerProperty(default = 1)
    

class CCloudTable(db.Model):
    ID = db.IntegerProperty()
    SourceUrl = db.LinkProperty()                       #关键字，不能重
    Title = db.StringProperty()
    TagList = db.StringListProperty()                       #标签
    Summary = db.StringProperty()                       #摘要（第一个推荐者有责任填写）
    CommendNumber = db.IntegerProperty(default=0)       #推荐用户数
    CollectNumber = db.IntegerProperty(default=0)       #收藏用户数
    CommentOnNumber = db.IntegerProperty(default=0)     #评论数
    Date = db.DateTimeProperty(auto_now_add=True)       #首次添加时间
    FirstCommend = db.UserProperty()
    LastCommend = db.UserProperty()
    FirstCollect = db.UserProperty()
    LastCollect = db.UserProperty()

class CMyCommendTable(db.Model):            #我的推荐
    CloudKey = db.ReferenceProperty(CCloudTable)
    TagList = db.StringListProperty()                       #标签
    LoginID = db.StringProperty()
    LoginAccount = db.UserProperty()
    HaveCommentOn = db.BooleanProperty(default=False)   #是否有评论
    CommentOn = db.StringProperty(multiline=True)       #评论或推荐
    Date = db.DateTimeProperty(auto_now_add=True)       #首次添加时间
    
class CMyCollectTable(db.Model):            #我的收藏
    CloudKey = db.ReferenceProperty(CCloudTable)
    TagList = db.StringListProperty()                       #标签
    LoginID = db.StringProperty()
    LoginAccount = db.UserProperty()
    HaveCommentOn = db.BooleanProperty(default=False)   #是否有评论
    CommentOn = db.StringProperty(multiline=True)       #评论或推荐
    Date = db.DateTimeProperty(auto_now_add=True)       #首次添加时间

    
class CLikeTable(db.Model):
    ID = db.IntegerProperty()
    SourceUrl = db.LinkProperty()                       #关键字，不能重
    Title = db.StringProperty()
    Type = db.StringProperty()                          #标签
    UserNumber = db.IntegerProperty()                   #用户数
    Date = db.DateTimeProperty(auto_now_add=True)       #首次添加时间
    
class CMyLikeTable(db.Model):
    SourceUrl = db.LinkProperty()                       #应对应于 CLikeTable 中的 SourceUrl
    Title = db.StringProperty()
    Type = db.StringProperty()                          #标签
    LoginName = db.StringProperty()
    HaveCommentOn = db.BooleanProperty(default=False)   #是否有评论
    CommentOn = db.StringProperty(multiline=True)       #评论或推荐
    Date = db.DateTimeProperty(auto_now_add=True)       #首次添加时间

class CToolTable(db.Model):
    ID = db.IntegerProperty()
    SourceUrl = db.LinkProperty()                       #关键字，不能重
    Title = db.StringProperty()
    Type = db.StringProperty()                          #分类
    UserNumber = db.IntegerProperty()                   #用户数
    Date = db.DateTimeProperty(auto_now_add=True)       #首次添加时间

class CMyToolTable(db.Model):
    ToolSourceUrl = db.LinkProperty()
    LoginName = db.StringProperty()
    Date = db.DateTimeProperty(auto_now_add=True)

class CFriendTable(db.Model):
    FriendName = db.StringProperty()
    ResponsionState = db.IntegerProperty(default=1)     #0未处理 1同意 2拒绝
    LoginName = db.StringProperty()
    ApplyType = db.IntegerProperty(default=0)           #申请类型 0我主动申请的 1对方申请的
    ApplyExplain = db.StringProperty()                  #申请说明
    Date = db.DateTimeProperty(auto_now_add=True)

class CInviteTable(db.Model):
    FriendEmail = db.StringProperty()
    MyName = db.StringProperty()
    Content = db.TextProperty()
    LoginName = db.StringProperty()
    Date = db.DateTimeProperty(auto_now_add=True)

class CSendOutMessage(db.Model):
    Title = db.StringProperty()
    Content = db.StringProperty(multiline=True)
    SendTo = db.StringListProperty()
    LoginName = db.StringProperty()
    State = db.IntegerProperty()                    #0发送成功 1失败
    Date = db.DateTimeProperty(auto_now_add=True)

class CReceiveMessage(db.Model):
    Title = db.StringProperty()
    Content = db.StringProperty(multiline=True)
    From = db.StringProperty()
    LoginName = db.StringProperty()
    State = db.IntegerProperty()                    #0未读 1已读
    Date = db.DateTimeProperty(auto_now_add=True)

class CDeleteMessage(db.Model):
    Title = db.StringProperty()
    Content = db.StringProperty(multiline=True)
    From = db.StringProperty()
    LoginName = db.StringProperty()
    State = db.IntegerProperty()
    Date = db.DateTimeProperty()
    DeleteDate = db.DateTimeProperty(auto_now_add=True)


class CGroupTable(db.Model):
    ID = db.IntegerProperty()
    GroupName = db.StringProperty()
    GroupExplain = db.StringProperty(multiline=True)
    LoginName = db.StringProperty()
    Date = db.DateTimeProperty(auto_now_add=True)

class CGroupUser(db.Model):
    GroupTableKey = db.ReferenceProperty(CMicroblogTable)
    LoginName = db.StringProperty()
    InviteState = db.IntegerProperty()          #0我邀请的 1对方想参加的
    ResponsionState = db.IntegerProperty()      #0未处理 1同意 2拒绝
    Date = db.DateTimeProperty(auto_now_add=True)

class CGroupTalkTable(CMicroblogTable):
    GroupTableKey = db.ReferenceProperty(CMicroblogTable)


